<?php

namespace app\admin\model;

use think\Db;
use app\admin\model\Common;
use think\Session;
use think\Validate;

class  Exachievement extends Common
{
	//已有成果添加
    public function WriteExachievement($param)
  {
    $info['achievement_name']=$param['achievement_name'];
    $info['publish_company']=$param['publish_company'];
    $info['publish_time']=$param['publish_time'];
    $info['train_id']=$param['train_id'];
    $info['status']=2;
    $info['status1']=2;
    $info['name']=$param['name'];
    $res=Db::table('oa_admin_exachievement')
                   ->insert($info);
       if($res){
            return true;
       }else{
       	return false;
       }
  }
    //已有成果列表
  public function ListExachievement($param)
  {
     $list=Db::table('oa_admin_exachievement')
        ->where('train_id',$param['train_id'])
        ->field('id,achievement_name,publish_company,publish_time,status')
        ->select();
     return $list;
  }
  //已有成果修改
   public function ReviseExachievement($param)
  {
     $id=$param['id'];
     $info['achievement_name']=$param['achievement_name'];
     $info['publish_company']=$param['publish_company'];
     $info['publish_time']=$param['publish_time'];
     $info['updata_time']=date('Y-m-d');
    $status=Db::table('oa_admin_exachievement')
            ->where('id',$id)
            ->field('status')
            ->select();
         if($status[0]['status']=='2')
          {
            $info['status']=4; 
            $info['ps']='已有成果';
          }if($status[0]['status']=='3'){
          	$info['status']=1; 
          }if($status[0]['status']=='1'){
          	$info['status']=1; 
          }
     $res= Db::table('oa_admin_exachievement')
          ->where('id',$id)
          ->find();
     if($res){
         Db::table('oa_admin_exachievement')
          ->where('id',$id)
          ->update([
            'achievement_name'=> $info['achievement_name'],
            'publish_company'=>$info['publish_company'],
            'publish_time'=>$info['publish_time'],
            'status'=> $info['status'],
            'updata_time'=>$info['updata_time'],
            'ps'=>$info['ps'],
          ]);

           return true;
          }else{
          	return false;
          }
  }
    //已有成果删除
    public function DeleteExachievement($param)
    {
    	$id=$param['id'];
    	$res= Db::table('oa_admin_exachievement')
          ->where('id',$id)
          ->delete();
          if($res){
          	return true;
          }else{
          	return false;
          }
    }
}